package level_ajax_query.db;

import java.sql.*;

/**
 * @Author Rookie Coder
 * @Description
 * @Date
 **/
public class JDBCUtil {

    static {
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public Connection getConnection(){
        Connection connection=null;
        String url = "jdbc:mysql:///springdb";
        String root = "root";
        String password = "140489lu";
        try {
           connection=DriverManager.getConnection(url,root,password);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return connection;
    }

    public void closeAll(Connection connection, PreparedStatement pst, ResultSet rs){
        if (connection!=null){
            try {
                connection.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
        if (pst!=null){
            try {
                pst.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
        if (rs!=null){
            try {
                rs.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }

    }


}
